/**
 * @Author: lusx
 * @Date:   08-03-2019 01:50:30
 * @Project: Govern督办
 * @Last modified by:   lusx
 * @Last modified time: 21-03-2019 10:49:00
 */
import * as Apis from "../../apis/govern";
import { Toast, ActionSheet, Tools } from "weaver-mobile";
const getLabel = Tools.getLabel;
const apisType = {//该对象注释不要删
  "2": Apis.attentTask,// 关注
  "3": Apis.getChangeTaskLayout, // 变更 id ,v
  "4": Apis.getDecomposeTaskLayout, //分解 id
  "5": Apis.getTaskInfo, //反馈 id
  "6": Apis.finishTask, //完成 taskid
  "7": Apis.cancelTask, //废弃 taskid
  "8": Apis.getTaskInfo, //催办 id
  "9": Apis.signingTask, //签收 taskid
  "11": ({id}) => {
     return Apis.getShareList({ id: id }).then(data => {
       return data;
        //btnStore.Toasts[params.btnType]();
      });
    //return Promise.resolve({status:"1"});
  }, // 共享
  "12": Apis.disAttentTask,// 取消关注
  "13": Apis.distribute, //下发 id
  "17": Apis.getActionSetting, // 延期  "taskid": id, "actiontype": actiontype
  "18": Apis.getActionSetting, // 办结/完结 "taskid": id, "actiontype": actiontype
  "1003": Apis.deleteTask,//删除 "taskid": id,
  "1004": Apis.reopenTask,// 重新开启 "taskid": id,
  //"0000" : Apis.getActionSetting,//流程触发
};
const loadingToast = (isloading) => {
  isloading ? (()=>{Toast.hide(); Toast.loading('Loading...',0)})() : Toast.hide();
}
const Btn = {
  root: id =>{
    loadingToast(true);
    return Apis.getCardBtnInfo(id).then(data => {
      loadingToast(false);
      if (data.status === "1") {
        return data;
      } else {
        Toast.hide();
        Toast.fail(data.error);
      }
    })
  },
  click: (id, key) => {
    loadingToast(true);
    return apisType[key]({ taskid: id, id: id, actiontype: key }).then(data => {
      loadingToast(false);
      if (data.status === "1") {
        return Promise.resolve(data);
      }else if(key === '1004' && data.status === "-2"){
        Toast.hide();
        Toast.info(`${getLabel("2012", "对不起,您暂时没有权限! ")}`);
      } else {
        Toast.hide();
        Toast.fail(data.error);
      }
    });
  }
};

//提交
const subApisType = {//该对象注释不要删
  "3": Apis.changeTask, // 变更 taskid ,v
  "4": Apis.decomposeTask, //分解提交 taskid,v
  "5": Apis.reportTask, //反馈提交 taskid,v
  "8": Apis.remindTask, //催办 taskid,v
  "11": Apis.addShare // 共享 id, v
};
const SubBtn = {
  click: (id, key, v) => {
    if (Array.isArray(v)) {
      v = { taskData: JSON.stringify(v) };
    } else {
      null;
    }
    return subApisType[key]({ taskid: id, id: id, ...v }).then(data => {
      if (data.status === "1") {
        return Promise.resolve(data);
      } else {
        Toast.fail(data.error);
      }
    });
  }
};
export default {
  Btn,
  SubBtn
};
